<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" id="html">
    <head>
        <title></title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <base href="<?= base_url(1); ?>" />
        <script type="text/javascript" src="<?= $config['res_url'] ?>/js/jquery.min.js?ver=<?= $config['version'] ?>"></script>   
        <script type="text/javascript" src="<?= $config['res_url'] ?>/js/jquery.autocomplete.js?ver=<?= $config['version'] ?>"></script>  
        <link type="text/css" rel="stylesheet" href="<?= $config['res_url'] ?>/css/jquery.autocomplete.css"  />   
        
        <link type="text/css" rel="stylesheet" href="css/main.css?v=<?= $config['version'] ?>"  /> 
        <script src="js/time.js?"></script>
		<script charset="utf-8" src="edit/kindeditor.js"></script>
		<script charset="utf-8" src="edit/lang/zh_CN.js"></script>
		<script charset="utf-8" src="edit/plugins/code/prettify.js"></script>

		<script type="text/css">
		.roleclass { color:#fff;}
		.objectclass { color:#fff;}
		</script>

        <script type="text/javascript">
            //var i = 0;
            function addp()
            {
            	var i = $(".autocomplete").length;
            	//alert("i = "+i);
                if (i < 4)
                {
                    i++;
                }
                else
                {
                    alert('up to four!');
                    return;
                }
                //alert("i = "+i);
                str = '<p id="p' + i + '">'
                	+'<input type="text" size="39"  placeholder="<?= translate('PLASE_INPUT_ITEM') ?>" '
                		+' name="row[item][]" id="itemid' + i + '" class="autocomplete" table="type_object" autocomplete="off" >'
                	+'<input type="text" size="8" placeholder="<?= translate('PLASE_INPUT_AMOUNT') ?>" '
                		+' name="row[amount][]" id="num' + i + '" >'
                	+'<?=translate('MAIL_EQUIPLEVEL')  ?>'
                	+'<select name="row[equiplevel][]" id="equiplevel'+i+'" >'
	                    +'<?php for ($i=0; $i<=10;++$i) { ?>'
	                    	+'<option value="<?=$i ?>"><?=$i ?></option>'
	                    +'<?php }?>'
                    +'</select>'
                	+'</p>';
                //alert(" str = "+str);
                $("#add").append(str);
                autocomplete();

                $("#num"+i).formValidator({empty: false, onshow: '<?= translate('MAIL_TIME_LIMIT_MIN_MAX') ?>'})
                	.inputValidator({type: 'number', min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});

            }
            function removep()
            {
            	var i = $(".autocomplete").length;
            	//alert("i = "+i);
                if (i > 0)
                {
					$("#p" + i).remove();
                }

            }

            function nameaddp()
        	{
        	    //得到当前数组的长度
        	    var i = $(".roleclass").length;
        		//alert(i);
        		var str=' <table width=100%  class="roleclass" id = "role'+i+'"> '+
	                '<tr><td>&nbsp;</td><td><?=translate("MAIL_ROLENAME") ?><input type="text" name="row[reciver_name]['+i+']"  size="25" id="reciver_name'+i+'" />'
	                +'<?=translate("MAIL_ROLEID") ?><input type="text" name="row[reciver_id]['+i+']"  size="25" id="reciver_id'+i+'" />'
	                +'</td></tr>'+
	                '</table>';
        	    //alert(str);	
        	    $("#rolenames").append(str);
        	}
        	function nameremovep()
        	{
        		var i = $(".roleclass").length;
        	    //alert(i);
        	    if (i > 1)
        	    {
            	    i = i - 1;
        	        //alert(i);
        	        $("#role" + i).remove();
        	        //i--;
        	    }
        	}
        	$(document).ready(function() {
        		//var area = $("#area").val();
    	 		//var rol = $("#rolename").val();
    	 		var ur = "<?= site_url("general/getSearchRoleName") ?>";
    	 		
	        		$("#website").autocomplete(
	        				$.ajax({
	        		    		type: "post",		
	        		    		url: ur,
	        					data:'areanum='+$("#area").val()+'&rolename='+$("#rolename").val(),
	        		    		success: function(data, textStatus){
	        						//alert('success');
	        						$("#showText").text(textStatus);
	        						//alert('('+data+')');
	        						var d = eval('('+data+')');

	        						for(var i = 0; i < d.length; ++i)
	        						{
		        						document.write('id:'+d.id+",name:"+d.name);
	        						}
	        						
	        						
	        		    		},	
	        		    			
	        	    		}),
		        		{
			        		delay:10,
			        		minChars:1,
			        		matchSubset:1,
			        		matchContains:1,
			        		cacheLength:10,
			        		onItemSelect:selectItem,
			        		onFindValue:findValue,
			        		formatItem:formatItem,
			        		autoFill:false
		        		}
	        		);
        		});
    		
        		function findValue(li) {
	        		if( li == null ) return alert("No match!");
	        		if( !!li.extra ) var sValue = li.extra[0];
	        		else var sValue = li.selectValue;
        		}
        		
        		function selectItem(li) { findValue(li);}
        		
        		function formatItem(row) { 
            		return row[0];//return row[0] + " (id: " + row[1] + ")"//如果有其他参数调用row[1]，对应输出格式Sparta|896
        		}
        		
        		function lookupAjax(){
	        		var oSuggest = $("#website")[0].autocompleter;
	        		oSuggest.findValue();
	        		return false;
        		} 
			/*
			
        	 $().ready(function() {
                 $("#website").autocomplete(

                 {
                     dataType:'json',
                     delay:10,
                     minChars:1,
                     matchSubset:1,
                     matchContains:1,
                     cacheLength:10,
                     //onItemSelect:selectItem,
                    // onFindValue:findValue,
                     //formatItem:formatItem,
                     autoFill:false,
                     parse: function(data) 
                     {
                         //解释返回的数据，把其存在数组里；在数据返回回来之后，还要在进行一次处理-》这是关键点；需要把data转换成json数据格式
                         var rows = new Array();
                         for (var i = 0; i < data.length; i++) {

                             rows[i] = { data: data[i], value: data[i].id, result: data[i].name };
                         }
                         return rows;
                     },
                     formatItem: function(item) {
                         return item.name;
                     }
                 }).result(function(event, item, formatted)
                     {
                         //内容显示在其他文本框上
                         $("#gift").val(item.id+'--'+item.name);
                     })
             }); 
          
        	 function getGift()
             {
                 alert($("#gift").val());
             }
             */
        </script>
    </head>
    <body>
        <?php include(VIEWPATH . 'common/main_header.php'); ?>
        <form action="" method="POST" id="rowForm">
            <table width="100%" border="0" cellspacing="1" cellpadding="0" class="tablegrid tableedit">
                <tr align="left">
                    <th colspan="2" align="left"><?= $title ?></th>
                </tr>
                <tr><td><?= translate('SELECT_PLATFORM') ?>:</td><td><?= $platformlist ?></td></tr>
                <tr><td><?= translate('SELECT_AREA') ?>:</td><td><?= $arealist ?></td></tr>
                
                <tr><td><?= translate('MAIL_RECEIVER') ?>:</td><td>&nbsp;</td></tr>
                 <tr>
                  <td>&nbsp;</td>  
                	<td id="rolenames">&nbsp;</td>	                					
                </tr>		
            
                <tr><td>&nbsp;</td><td >
	                    <input type="button" onclick="nameaddp()" value="<?= translate('ADD_ONE') ?>" />
	                    <input type="button" onclick="nameremovep()" value="<?= translate('REMOVE_ONE') ?>" />
                </td></tr> 
                  
                <tr><td><?= translate('MAIL_TITLE') ?>:</td>
                <td><input type="text" name="row[mail_title]" id="mail_title" size="25" /></td></tr> 
        <!--    <tr><td><?= translate('MAIL_TIME_LIMIT') ?>:</td>
                	<td>
					<select name="row[keep_time]" id="keep_time" >
				      	  <?php foreach ($keeptime as $key => $value) {?>
				      	  	<option value="<?=$key ?>"><?=$value ?></option>
				      	  <?php }?>
				      	  <option value="-1"><?= translate('FOREVER') ?></option>
                   	 	</select>&nbsp;<?= translate('DAY') ?>
                	</td>
                </tr>
        -->    
                <tr><td><?= translate('MAIL_CONTENT') ?>:</td>
                <td>
                <!--  
                	<textarea name="row[mail_content]" id="mail_content" cols="50" rows="5"></textarea>
                -->
                <textarea cols="70" rows="13" name="row[mail_content]" id="mail_content"></textarea></td></tr> 
                
                <tr><td><?= translate('MAIL_SEND_REASON') ?>:</td><td><input type="text" name="row[reason]" id="reason" size="65" /></td>
                </tr>
                
                <tr><td><?= translate('MAIL_ATTACH') ?>:</td><td id="add">
                <p id="p">
                       <input type="button" onclick="addp()" value="<?= translate('ADD_ONE') ?>" />
                       <input type="button" onclick="removep()" value="<?= translate('REMOVE_ONE') ?>" />
                </p>
                </td></tr>
                <tr><td>&nbsp;</td><td>&nbsp;</td></tr> 
                <tr><td></td><td>
                
                <!-- <input type="reset" value="<?= translate('RESET') ?>" id="reset"/>  -->
                &nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="submit" value="<?= translate('SUBMIT') ?>" id="submit"/>
                        </td></tr>
            </table>
        </form>
        
	 <!--       <form id="form1" runat="server">
	    选择: <input type="text" id="website" /><br>
	    名字: <input type="text" id="gift" name="gift"/><br>
	    <input type="button" value="提交"  onclick="getGift()"/>
	    </form>  -->
        
        <script type="text/javascript">
            SG.init("core.form", function() {
                $.formValidator.initConfig({formid: "#rowForm", submitonce: true});
                $("#area_host").formValidator({empty: false, onshow: '<?= translate('PLASE_SELECT') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
                $("#platform").formValidator({empty: false, onshow: '<?= translate('PLASE_SELECT') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
                $("#reciver_name").formValidator({empty: false, onshow: '<?= translate('PLASE_WRITE') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
                $("#mail_title").formValidator({empty: false, onshow: '<?= translate('PLASE_WRITE') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
                $("#mail_content").formValidator({empty: false, onshow: '<?= translate('PLASE_WRITE') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
                //$("#keep_time").formValidator({empty: false, onshow: '<?= translate('MAIL_TIME_LIMIT_MIN_MAX') ?>'}).inputValidator({type: 'number', min: 1, max: 30, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
                $("#reason").formValidator({empty: false, onshow: '<?= translate('PLASE_WRITE') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
            });
        </script>
    </body>
</html>
